import axios from 'axios';
import {API_NEW_VERSION} from '../api';

var qs = require('qs');

let basePath = '/api/v1.0/admin/';

/**
 * 路径  start
 * ----------------------------------------------------------------------------------------------------------------------
 */

const ADDRESSES = basePath + 'address';
const ADDRESSE = basePath + 'address/';

const ORGANIZATION_LIST = basePath + 'organizations/list';
const ADDRESS_BATCH_DELETE = basePath + 'address_batch_delete/';

const ADDRESS_MODIFYT_NOT_ISDEFAULT = basePath + 'address_modify_not_is_default';

const ADDRESS_MODIFYT_ISDEFAULT = basePath + 'address_modify_is_default/';

const ADDRESSBYUSERID = basePath + 'address_by_userid';

const PARTNER_BY_INVITECODE = API_NEW_VERSION + 'partners_by_invitecode';

const DICTENTITY = basePath + 'fdict_entitys/fdict_entitys';

const MEB_USER_RESET_PASSWORD_BY_ID = basePath + `meb_users/reset_passwrod_by_id`;

const ADDRESS_DICTS = basePath + `address_dicts`;

const MEB_USER_BY_USERID = basePath + 'meb_users_byuserid';

const MEBPERSONALCENTER = basePath + `mebpersonalcenter`;

const MEB_USERS = basePath + `meb_users/`;

const MEB_USER_CHANGE_STATUS = basePath + 'meb_users_change_status';

const MEB_USERS_MODIFY_LOGICSTATIC = basePath + '/meb_users_logic_static';

// 账户明细

const FUNDMEBACCT_MEBID = API_NEW_VERSION + '/fundmebacct/mebid';
// 交易 明细
const FUNDMEBACCTTFLOW_BY_USERID = API_NEW_VERSION + '/fundmebaccttflow/by/';
const ORDERS_RECEIVABLES = API_NEW_VERSION + 'orders/receivable';

// 充值 明细
const FUNDMEBACCTRFLOWS_FIND_BY_MEBID = API_NEW_VERSION + '/fundmebacctrflows/find/by/';
const FUNDMEBACCTRFLOWS = API_NEW_VERSION + '/fundmebacctrflows';

// 优惠券明细
const COUPON_LOGS = API_NEW_VERSION + 'coupon_logs';

const COUPONS_COUNT_BY_PHONE_AND_STATUS = API_NEW_VERSION + 'coupons_cont_by_phone_and_status';

/**
 * 路径  end
 * --------------------------------------------------------------------------------------------------------------------
 */
// 根据手机号获取优惠券领取记录
export const searchCouponLog = params => {
  return axios.get(COUPON_LOGS, {params: params});
};
// 根据ID，更改密码
export const countAmountByPhoneAndStatus = (phone, status) => {
  return axios.post(COUPONS_COUNT_BY_PHONE_AND_STATUS, qs.stringify({phone: phone, status: status}));
};

// 根据USERID搜索充值 记录
export const searchFundMebacctRflows = params => {
  return axios.get(FUNDMEBACCTRFLOWS, {params: params});
};

// 根据USERID获取充值记录
export const getMemberUserAcctRflow = userid => {
  return axios.get(FUNDMEBACCTRFLOWS_FIND_BY_MEBID + userid);
};

/**
 * 根据USERID搜索交易明细列表（应收单）
 * @param params
 * @returns {AxiosPromise}
 */
export const searchFundMebacctTflows = params => {
  return axios.get(ORDERS_RECEIVABLES, {params: params});
};

// 根据USERID获取账户总资金列表
export const getMemberUserAcct = id => {
  return axios.get(FUNDMEBACCT_MEBID, {params: {mebid: id}});
};

//
export const getMemberUserAcctTflow = userid => {
  return axios.get(FUNDMEBACCTTFLOW_BY_USERID + userid);
};

// 获取列表
export const getMemberUsers = params => {
  return axios.get(MEB_USERS, {params: params});
};
// 根据ID，获取详情
export const getMemberUser = id => {
  return axios.get(MEB_USERS + id.join(','));
};

// 保存
export const saveMemberUser = (params) => {
  return axios.post(MEBPERSONALCENTER, params);
};
// 根据ID，更改密码
export const resetPasswordById = (id, password) => {
  return axios.post(MEB_USER_RESET_PASSWORD_BY_ID, qs.stringify({id: id, password: password}));
};

// 批量启用/停用
export const batchStart = (id, status) => {
  return axios.post(MEB_USER_CHANGE_STATUS, qs.stringify({id: id.join(','), status: status}));
};
// 批量删除
export const batchDel = (id, logicStatus) => {
  return axios.post(MEB_USERS_MODIFY_LOGICSTATIC, qs.stringify({id: id.join(','), logicStatus: logicStatus}));
};
// 根据ID，获取地址列表
export const getAddresses = id => {
  let myid = `pid=` + id;
  return axios.get(ADDRESS_DICTS, {params: {filters: myid}});
};

// 查询字典项
export const searchDictEntitys = id => {
  return axios.get(DICTENTITY, {params: {dictCode: id}});
};

// 根据邀请码，获取合伙人详情
export const findByInviteCode = id => {
  return axios.get(PARTNER_BY_INVITECODE, {params: {inviteCode: id}});
};

// 根据USERID，获取会员信息
export const getUserByUserId = userId => {
  return axios.get(MEB_USER_BY_USERID, {params: {userId: userId}});
};
// 根据userid，获取通信录
export const getAddressByUserId = userId => {
  return axios.get(ADDRESSBYUSERID, {params: {userId: userId}});
};

// 根据ID，设置 默认
export const modifyIsDefault = (id, userId, addressType) => {
  return axios.get(ADDRESS_MODIFYT_ISDEFAULT, {params: {id: id, userId: userId, addressType: addressType}});
};
// 根据ID，取消 默认
export const modifyIsNotDefault = (id, userId, addressType) => {
  return axios.get(ADDRESS_MODIFYT_NOT_ISDEFAULT, {params: {id: id, userId: userId, addressType: addressType}});
};

// 批量删除地址
export const batchAddressDel = id => {
  return axios.delete(ADDRESS_BATCH_DELETE + id.join(','));
};

// 保存地址
export const saveAddress = (params) => {
  return axios.post(ADDRESSES, params);
};

// 根据ID，获取用户地址
export const getUserAddress = id => {
  return axios.get(ADDRESSE + id);
};

// 根据条件获取地址址列表
export const searchAddresses = params => {
  return axios.get(ADDRESSES, {params: params});
};
// 获取机构列表
export const searchOrganization = params => {
  return axios.get(ORGANIZATION_LIST, {params: params});
};
